package com.example.domain.strategy.model.entity;

import com.example.types.common.Constants;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * @Author: 三石
 * @desc: 策略实体
 * @Date: 2024-07-18-22:27
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StrategyEntity implements Serializable {

    /** 抽奖策略ID */
    private Long strategyId;
    /** 抽奖策略描述 */
    private String strategyDesc;
    /** 抽奖规则模型 rule_weight,rule_blacklist */
    private String ruleModels;

    @JsonIgnore
    public String[] ruleModels() {
        if (StringUtils.isBlank(ruleModels)) return new String[0];
        return ruleModels.split(Constants.SPLIT);
    }

    @JsonIgnore
    public String getRuleWeight() {
        String[] ruleModels = this.ruleModels();
        for (String ruleModel : ruleModels) {
            if ("rule_weight".equals(ruleModel))
                return ruleModel;
        }
        // 返回 null 说明没有 rule_weight 规则
        return null;
    }

}
